package com.open.capacity.controller;

import com.open.capacity.common.web.Result;
import com.open.capacity.model.MessageModel;
import com.open.capacity.service.MessageService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author: y_022
 * @date: 11:06-2021/7/19
 * @description:
 */
@Slf4j
@Api(tags = "COLLECTION API")
@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageService;
    private static final String KEY_PRE_MESSAGE_COUNT = "KEY_PRE_MESSAGE_COUNT"; //缓存中的新下单消息的前缀
    @GetMapping("/getMessageCount")
    public Result getMessageCount(MessageModel messageModel) {
        try {
           Integer count =  messageService.getMessageCount(messageModel);
           return Result.succeed(count,"查询消息总数成功！");
        } catch (Exception e) {
            log.error("查询异常",e);
        }
            return Result.succeed("查询失败");
    }
    @GetMapping("/getMessage")
    public Result getMessage(MessageModel messageModel,Integer page,Integer limit){
        try{
            String  message = messageService.getMessage(messageModel);
            return Result.succeed(message,"查询成功！");
        }catch (Exception e){
            log.error("消息查询异常",e);
        }
        return Result.failed("查询失败！");
    }
    @PostMapping("/deleteMessage")
    public Result deleteMessage(MessageModel messageModel){
        try{
            messageService.deleteMessage(messageModel);
            return Result.succeed("操作成功！");
        }catch (Exception e){
            log.error("删除消息失败！",e);
        }
        return Result.failed("操作失败！");
    }
}
